$(document).ready(function () {
    bsjd.onload();
})
var bsjd = (function () {
	var init = function () {
    	layui.use('form', function(){
			  var form = layui.form
		});
    }
    return {
        onload : function () {
        	init();
            bsjd.tableDataBsjd();
            bsjd.tableDataLsbs();
            bsjd.formTab();
            bsjd.dateShow();
        },
       /*表格数据交互*/
      tableDataBsjd: function() {//办税进度及结果查询
 		var data = [{
 				"number": "1",
 				"ywID": "1807110700334001",
 				"ywName": "跨区域涉税事项报告",
 				"sqDate":"2018-07-11 09:23:15",
 				"state": "已完成",
 				"operation":null
 			},
 			{
 				"number": "2",
 				"ywID": "1807110700334001",
 				"ywName": "跨区域涉税事项报告",
 				"sqDate":"2018-07-11 09:23:15",
 				"state": "已完成",
 				"operation":null
 			},
 			{
 				"number": "3",
 				"ywID": "1807110700334001",
 				"ywName": "跨区域涉税事项报告",
 				"sqDate":"2018-07-11 09:23:15",
 				"state": "已办理",
 				"operation":null
 			},
 			{
 				"number": "4",
 				"ywID": "1807110700334001",
 				"ywName": "跨区域涉税事项报告",
 				"sqDate":"2018-07-11 09:23:15",
 				"state": "已退回",
 				"operation":null
 			}
 		];
 		$('#wepBsjd').DataTable({
 			"data": data,
 			"columnDefs": [
 				{
 					"targets": -1,
 					"data": null,
 					"render": function(data, type, full, meta) {
 						return '<a href="#"><span class="btn wxl_bg_lan1">查看文书</span></a>'
 					}
 				}
 			],
 			"columns": [
 			    {
 					"data": "number"
 				},
 				{
 					"data": "ywID"
 				},
 				{
 					"data": "ywName"
 				},
 				{
 					"data": "sqDate"
 				},
 				{
 					"data": "state"
 				},
 				{
 					"data": "operation"
 				}
 			],
// 			"paging": false,
 			"info": false,
 			"ordering": false,
 			"lengthChange": false,
 			"searching": false,
 			"fnInitComplete": function (oSettings, json) {/*判断认证状态显示字体颜色*/
	            for(var i=0;i<$('#wepBsjd tbody tr').length;i++){
	            	if($('#wepBsjd tbody tr').eq(i).find('td').eq(4).text() == "已完成"){
	            		$('#wepBsjd tbody tr').eq(i).find('td').eq(4).addClass('font1')
	            	}else if($('#wepBsjd tbody tr').eq(i).find('td').eq(4).text() == "已退回"){
	            		$('#wepBsjd tbody tr').eq(i).find('td').eq(4).addClass('font2')
	            	}else{
	            		$('#wepBsjd tbody tr').eq(i).find('td').eq(4).addClass('font3')
	            	}
	            }
	        }
 		});
     },
     tableDataLsbs: function() {//历史办税操作查询
 		var data = [{
 				"number": "1",
 				"ywID": "1807110700334001",
 				"ywName": "跨区域涉税事项报告",
 				"sqDate":"2018-07-11 09:23:15",
 				"state": "已完成",
 				"operation":null
 			},
 			{
 				"number": "2",
 				"ywID": "1807110700334001",
 				"ywName": "跨区域涉税事项报告",
 				"sqDate":"2018-07-11 09:23:15",
 				"state": "已完成",
 				"operation":null
 			},
 			{
 				"number": "3",
 				"ywID": "1807110700334001",
 				"ywName": "跨区域涉税事项报告",
 				"sqDate":"2018-07-11 09:23:15",
 				"state": "已办理",
 				"operation":null
 			},
 			{
 				"number": "4",
 				"ywID": "1807110700334001",
 				"ywName": "跨区域涉税事项报告",
 				"sqDate":"2018-07-11 09:23:15",
 				"state": "已退回",
 				"operation":null
 			}
 		];
 		$('#wepLsbs').DataTable({
 			"data": data,
 			"columnDefs": [
 				{
 					"targets": -1,
 					"data": null,
 					"render": function(data, type, full, meta) {
 						return '<a href="#"><span class="btn wxl_bg_lan1">查看文书</span></a>'
 					}
 				}
 			],
 			"columns": [
 			    {
 					"data": "number"
 				},
 				{
 					"data": "ywID"
 				},
 				{
 					"data": "ywName"
 				},
 				{
 					"data": "sqDate"
 				},
 				{
 					"data": "state"
 				},
 				{
 					"data": "operation"
 				}
 			],
// 			"paging": false,
 			"info": false,
 			"ordering": false,
 			"lengthChange": false,
 			"searching": false,
 			"fnInitComplete": function (oSettings, json) {/*判断认证状态显示字体颜色*/
	            for(var i=0;i<$('#wepLsbs tbody tr').length;i++){
	            	if($('#wepLsbs tbody tr').eq(i).find('td').eq(4).text() == "已完成"){
	            		$('#wepLsbs tbody tr').eq(i).find('td').eq(4).addClass('font1')
	            	}else if($('#wepLsbs tbody tr').eq(i).find('td').eq(4).text() == "已退回"){
	            		$('#wepLsbs tbody tr').eq(i).find('td').eq(4).addClass('font2')
	            	}else{
	            		$('#wepLsbs tbody tr').eq(i).find('td').eq(4).addClass('font3')
	            	}
	            }
	        }
 		});
     },
     /*日期显示*/
        dateShow:function(){
        	layui.use('laydate', function(){
			  var laydate = layui.laydate;
			  function dateObj(dom1,dom2){//结束时间不小于开始时间
					var startDate   = laydate.render({
						elem: dom1,
						done:function(value,date){
							if( value !== '' ){
								endDate.config.min.year = date.year;
								endDate.config.min.month = date.month - 1;
								endDate.config.min.date = date.date;
							}else{
								endDate.config.min.year = '';
								endDate.config.min.month = '';
								endDate.config.min.date = '';
							}
						}
					});
					var endDate  = laydate.render({
						elem: dom2,
						done:function(value,date){
							if( value !== '' ){
								startDate.config.max.year = date.year;
								startDate.config.max.month = date.month - 1;
								startDate.config.max.date = date.date;
							}else{
								startDate.config.max.year = '';
								startDate.config.max.month = '';
								startDate.config.max.date = '';
							}
						}
					});
				}
				dateObj('#wep_date1','#wep_date2');
				dateObj('#wep_date3','#wep_date4');
			})
        },
        /*tab选项卡*/
       formTab:function(){
	       	$(".wep_table_tab span").click(function(){
	       		$(this).addClass("active").siblings("span").removeClass("active");
				var n=$(this).index();
				$(".wep_xxcx_box").eq(n).show().siblings(".wep_xxcx_box").hide();
				
			})
	    }
    }
})();